#!/bin/sh
#
#check platform and compiler

OUTPUT=$1

CXX=
CXXFLAGS=
SHARED_LDFLAGS=
SHARED_CFLAGS=

if test -z "$OUTPUT"; then
  echo "usage: $0 <output-filename>" >&2
  exit 1
fi

# Delete existing output, if it exists
rm -f $OUTPUT
touch $OUTPUT


# check OS
if test -z "$TARGET_OS"; then
    TARGET_OS=`uname -s`
fi

case "$TARGET_OS" in
    Linux)
        OS=LINUX
        CXX=g++
        LDFLAGS="-pthread -lrt"
        CXXFLAGS=
        SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
        SHARED_CFLAGS="-fPIC"
        ;;
    *)
        echo "Unknown platform!" >&2
        exit 1
esac

#check compiler
$CXX -v > /dev/null 2>&1
if [ "$?" != 0 ]; then
    echo "$CXX not found!"
    exit 1
fi


DIRS="util db log"
DBLIBFILES=`find $DIRS -name '*.cxx' -print | sort | tr "\n" " "`

mkdir bin lib bin/test > /dev/null 2>&1

echo "SOURCES=$DBLIBFILES" >> $OUTPUT
echo "CXX=$CXX" >> $OUTPUT
echo "PLATFORM=$OS" >> $OUTPUT
echo "LDFLAGS=$LDFLAGS" >> $OUTPUT
echo "CXXFLAGS=$CXXFLAGS" >> $OUTPUT
echo "SHARED_CFLAGS=$SHARED_CFLAGS" >> $OUTPUT
echo "SHARED_EXT=$SHARED_EXT" >> $OUTPUT
echo "SHARED_LDFLAGS=$SHARED_LDFLAGS" >> $OUTPUT
